<?php
header("Content-Type: text/html; charset=utf-8");
error_reporting(0);
include_once ("common/mysql.class.php");
include_once ("config/config.php");
include_once ('common/function.php');
$db = new mysql($mydbhost, $mydbuser, $mydbpw, $mydbname, ALL_PS, $mydbcharset);
?>
<!DOCTYPE HTML>
<html>
	<head>
		<title>后台管理-订单列表</title>
		<meta http-equiv=content-type content="text/html; charset=utf8">
		<link href="http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
		
		<style>
			.pagenavi { margin:15px auto; padding:0 15px; height:30px; line-height:30px; }
			.pagenavi.left { text-align:left; }
			.pagenavi.center { text-align:center; }
			.pagenavi a,.pagenavi span { display:inline-block; padding:0 8px; height:30px; line-height:30px; }
			.pagenavi a { height:28px; line-height:28px; border:1px solid #d3d3d3; }
			.pagenavi a.current { background:#d3d3d3; color:#333333; }
		</style>
	</head>
	<body>
		<!-- 主体 -->
		<div class="table-responsive l-98b">  
			<div class="panel panel-default">
				<div class="panel-heading">
					后台管理 &gt;&gt; 订单列表
				</div>
				<div class="panel-body ">
					<form action="" method="get" class="form-inline">
						<!--search start-->
					 	<div class="form-group">
					    	<label class="sr-only" for="ordersn">订单号</label>
					    	<input type="text" class="form-control" id="ordersn" name="ordersn" placeholder="请输入订单号" 
					    	value="<?php echo $_REQUEST['ordersn']; ?>" >
					  	</div>
					  	<div class="form-group">
					    	<select class="form-control" name="delivery">
					    		 <option value="">请选择配送方式</option>
							  	 <option value="1" <?php if ($_REQUEST['delivery'] == 1) echo ' selected="selected"'; ?>>校园配送</option>
								 <option value="2" <?php if ($_REQUEST['delivery'] == 2) echo ' selected="selected"'; ?>>快递配送</option>
							</select>
					  	</div>
					  	<div class="form-group">
					  	<button type="submit" class="btn btn-primary">搜索</button>
						<!--search end-->
						</div>
						<table class="table table-striped table-bordered" style="margin-top:10px;">
							<thead>
							<tr>
						  	<th width="50">ID</th>
								<th>订单号</th>
								<th>书籍金额</th>
								<th>运费</th>
								<th>总金额</th>
								<th>下单人</th>
								<th>支付方式</th>
							</tr>
							</thead>
							<tbody>
								<?php
									$sql="select * from php_orders where 1=1 ";
									if(!empty($_REQUEST['ordersn'])){
										$sql.=" and  ordersn like '%".$_REQUEST['ordersn']."%' ";
									}
									if(!empty($_REQUEST['delivery'])){
										$sql.=" and  delivery = ".$_REQUEST['delivery'];
									}
									$sql.=" order by orderid desc";
									
									//page start
									$db->query($sql);
									$page_total = $db->db_num_rows();
									$page_perpage = 5;
									$page_current = $_GET['page'] ? intval($_GET['page']) : 1;  //当前第几页
									if (strpos($_SERVER['REQUEST_URI'],'page=')){
										$page_url = preg_replace('/page=(\d+)/', 'page=#page#', $_SERVER['REQUEST_URI']);	
									} elseif (strpos($_SERVER['REQUEST_URI'],'?')){
										$page_url = $_SERVER['REQUEST_URI'] . '&page=#page#';
									} else {
										$page_url = $_SERVER['REQUEST_URI'] . '?page=#page#';
									}
									$page_class=array('class' => 'pagenavi');
									$page_html = page($page_total, $page_perpage, $page_current, $page_url,$page_class );
									//page end
									
									 $db->query($sql.' limit '.($page_current-1)*$page_perpage.','.$page_perpage);
									while($row = $db->fetch_array()){
								?>
						
								<tr>
									<td><?php echo $row['orderid']; ?></td>
									<td><?php echo $row['ordersn']; ?></td>
									<td><?php echo number_format($row['total_pricemoney'], 2); ?></td>
									<td><?php echo number_format($row['freight'], 2); ?></td>
									<td><?php echo number_format($row['total_fee'], 2); ?></td>
									<td><?php echo $row['usertruename']; ?></td>
									<td>
										<?php
											if ($row['delivery'] == 1) {
												echo "校园配送";
											} else if ($row['delivery'] == 2) {
												echo "快递配送";
											}
										?>									
									</td>
								</tr>
								<?php
								}
								?>
								<tr>
									<th colspan="7"><?php echo $page_html; ?></th>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
			</div>
		</div>
		
		
	</body>
</html>									